﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace ProjectNocturnalFool
{
    public sealed class MouseImageMgr
    {
        #region Fields

        ParticleEngine particleEngine;

        SpriteBatch spriteBatch;

        Texture2D cursorImage;

        /// <summary>
        /// Allocate ourselves.
        /// We have a private constructor, so no one else can.
        /// </summary>
        static readonly MouseImageMgr _instance = new MouseImageMgr();

        /// <summary>
        /// Access SiteStructure.Instance to get the singleton object.
        /// Then call methods on that instance.
        /// </summary>
        public static MouseImageMgr Instance
        {
            get { return _instance; }
        }

                
        /// <summary>
        /// Gets the Spritebatch
        /// </summary>
        public SpriteBatch SpriteBatch
        {
            get { return spriteBatch; }
        }
        
        /// <summary>
        /// Constructs the Mouse Image Manager
        /// </summary>
        public MouseImageMgr()
        {

        }

        /// <summary>
        /// Initializes the screen manager component.
        /// </summary>
        public void Initialize()
        {
        }

        /// <summary>
        /// Load your graphics content.
        /// </summary>
        public void LoadContent()
        {
            // Load content belonging to the screen manager.
            ContentManager content = TacticsGame.Instance.Content;

            spriteBatch = new SpriteBatch(TacticsGame.Instance.GraphicsDevice);

            List<Texture2D> textures = new List<Texture2D>();
            textures.Add(content.Load<Texture2D>(Constants.TextureParticleStar));
            textures.Add(content.Load<Texture2D>(Constants.TextureParticleDiamond));
            textures.Add(content.Load<Texture2D>(Constants.TextureParticleCircle));
            particleEngine = new ParticleEngine(textures);

            cursorImage = content.Load<Texture2D>(Constants.TextureMouseCursorSword);
        }

        #endregion

        /// <summary>
        /// Draws Cursor and/or related particles.
        /// </summary>
        public void Draw(GameTime gameTime)
        {                      
            //Draw Cursor
            int x, y;

            x = Mouse.GetState().X;
            y = Mouse.GetState().Y;
            
            Rectangle sourceRectangle = new Rectangle(0, 0, cursorImage.Height, cursorImage.Width);

            spriteBatch.Begin();        
            spriteBatch.Draw(cursorImage, new Vector2(x,y), Color.White);
            spriteBatch.End();

           // particleEngine.Draw();
        }

        /// <summary>
        /// Draws Cursor and/or related particles.
        /// </summary>
        public void Update(GameTime gameTime)
        {
            int x, y;
            if (InputMgr.Instance.isMouseClickUp(Click.Left))
            {
                x = Mouse.GetState().X;
                y = Mouse.GetState().Y;
                //particleEngine.GenerateNewBurstParticle(x, y);
            }

            //particleEngine.Update();
            
        }

    }
}
